package com.sh.data.engine.application.model.request.normalization;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * @author : changkong
 * @date : 2022/1/17
 */
@Data
@Builder
@Schema
@NoArgsConstructor
@AllArgsConstructor
public class SaveNewModelRequest {

    @NotBlank
    @Schema(description = "中文名", requiredMode = Schema.RequiredMode.REQUIRED)
    @Pattern(
        regexp = "^[\\u4e00-\\u9fa5_a-zA-Z0-9]{2,32}$",
        message = "模型中文名称长度在2-32之间, 仅支持中文英文字母数字下划线")
    private String cnName;

    @NotBlank
    @Schema(description = "英文名", requiredMode = Schema.RequiredMode.REQUIRED)
    @Pattern(regexp = "^[_a-zA-Z0-9]{2,64}$", message = "模型英文名称长度在2-64之间, 仅支持英文字母数字下划线")
    private String enName;

    @Schema(name = "schema", requiredMode = Schema.RequiredMode.NOT_REQUIRED, description = "sap require schema")
    private String schema;

    @NotBlank
    @Schema(title = "当前选择的模型类型", description = "如ods dwd dim", requiredMode = Schema.RequiredMode.REQUIRED)
    private String modelType;

    @Schema(description = "数据密级", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    private Long dataSecretId;

    @NotNull
    @Schema(title = "是否支持富文本", description = "", requiredMode = Schema.RequiredMode.REQUIRED)
    private boolean supportRtf;

    // 主题
    @NotNull
    @Schema(description = "主题id", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long themeId;

    // 生命周期
    @NotNull
    @Schema(description = "生命周期", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer LifeCycle;

    // 属性配置(字段列表)
    @NotEmpty
    @Schema(description = "字段列表", requiredMode = Schema.RequiredMode.REQUIRED)
    private List<Field> fields;

    @Data
    @Schema(description = "模型字段")
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Field {

        @NotEmpty
        @Schema(description = "字段名", requiredMode = Schema.RequiredMode.REQUIRED)
        private String fieldName;

        @NotEmpty
        @Schema(description = "字段描述", requiredMode = Schema.RequiredMode.REQUIRED)
        private String fieldDesc;

        @NotEmpty
        @Schema(description = "字段类型", requiredMode = Schema.RequiredMode.REQUIRED)
        private String fieldType;

        @NotEmpty
        @Schema(description = "是否必填", requiredMode = Schema.RequiredMode.REQUIRED)
        private Boolean required;

        @NotEmpty
        @Schema(description = "是否分区", requiredMode = Schema.RequiredMode.REQUIRED)
        private Boolean isPartition;
    }
}
